//
//  UserManager.m
//  Demo
//
//  Created by 龚碧容 on 2017/9/16.
//  Copyright © 2017年 hwd. All rights reserved.
//

#import "UserManager.h"

@implementation UserManager

+ (UserManager *)sharedManager{
    
    static UserManager *manager = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        manager=[[UserManager alloc] init];
    });
    return manager;
}

- (BOOL)isUserLogin{
    NSString *userId=[[NSUserDefaults standardUserDefaults] objectForKey:kLoginToken];
    if (![self isNull:userId]||userId.length==0) {
        return NO;
    }
    return YES;
}

- (BOOL)isNull:(id)object{
    // 判断是否为空串
    if ([object isEqual:[NSNull null]]) {
        return NO;
    }else if ([object isKindOfClass:[NSNull class]]){
        return NO;
    }else if (object==nil){
        return NO;
    }
    return YES;
}

- (void)loginOut{
    
    if (![[[NSUserDefaults standardUserDefaults] objectForKey:kIsRememberAccount] boolValue]) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:kLoginPhoneName];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:kLoginPassport];
    }

    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kLoginToken];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kLoginUserId];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kVipNumber];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:kJrUserId];
    
    NSString *addStr=[[NSUserDefaults standardUserDefaults] objectForKey:kDefaultAddress];
    if (addStr.length!=0) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:kDefaultAddress];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:kDefaultEnddic];
    }
}

@end
